{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def reverse(self, x: int) -> int:\n",
    "        s = str(x)\n",
    "        flag = ''\n",
    "        if s[0] == '-':\n",
    "            flag = s[0]\n",
    "            s = s[1:]\n",
    "\n",
    "        re_x = int(flag+s[::-1])\n",
    "        print(x)\n",
    "        print(re_x)\n",
    "        if re_x >= 2**31 or re_x < -2**31:\n",
    "            return 0\n",
    "        else:\n",
    "            return re_x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-32768\n",
      "-86723\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "-86723"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.reverse(-2**15)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3",
   "language": "python",
   "name": "py3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
